package com.john.seckill.utils;

import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.stereotype.Component;
import org.thymeleaf.spring5.context.SpringContextUtils;

@Component
public class MD5Util {
    private static final String salt = "1a2b3c4d";

    public  static String md5(String src){
        return DigestUtils.md5Hex(src);
    }

    public static String inputPassToFromPass(String inputPass){
        // 进行混淆
        String str = ""+salt.charAt(0)+salt.charAt(2)+inputPass+salt.charAt(5)+salt.charAt(4);
        return md5(str);
    }

    public static String formPassToDBPass(String fromPass,String salt){
        String str = ""+salt.charAt(0)+salt.charAt(2)+fromPass+salt.charAt(5)+salt.charAt(4);
        return md5(str);
    }
    public static String inputPassToDBPass(String inputPass,String salt){
        final String fromPass = inputPassToFromPass(inputPass);
        return formPassToDBPass(fromPass,salt);//c6c87c29ca9573c07bd266acdbd766a7
    }

    public static void main(String[] args) {
        //52f898c27511518b951a737149783901
        System.out.println(inputPassToFromPass("123456789"));
        System.out.println(formPassToDBPass("52f898c27511518b951a737149783901","1a2b3c4d"));
        System.out.println(inputPassToDBPass("123456789","1a2b3c4d"));
    }
}
